package 贪心;

public class 贪心3_最大子数组和 {
    public int maxSubArray(int[] nums) {
        int sum=0;
        int res= Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            if(sum<0){
                sum=0;
            }
            sum+=nums[i];
            res=Math.max(res,sum);
        }
        return res;
    }
    public static void main(String[] args) {
        int[] nums={-2};
        贪心3_最大子数组和 t=new 贪心3_最大子数组和();
        System.out.println(t.maxSubArray(nums));
    }
}
